﻿namespace WMS6.Web.Common
{
    using System;
    using System.Data;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web.UI.HtmlControls;
    using WMS6.Web;

    public class GetWHAjax : BasePage
    {
        protected HtmlForm form1;

        private void AjaxResponse(string StrHtml)
        {
            StringBuilder StrBegin = new StringBuilder();
            StringBuilder StrEnd = new StringBuilder();
            string StrWhDescr = string.Empty;
            if (base.UserInfo.Preference.Lang.ToUpper() == "ZH-CN")
            {
                StrWhDescr = "请选择仓库";
            }
            else if (base.UserInfo.Preference.Lang.ToUpper() == "ZH-TW")
            {
                StrWhDescr = "請選擇倉庫";
            }
            else
            {
                StrWhDescr = "Please select the warehouse";
            }
            StrBegin.AppendFormat("<table width=\"520\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr> <td align=\"center\" class=\"warehousbg_01\"><table width=\"96%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"right\"><a href=\"#\" onclick=\"DivCloseAll();\" onFocus=\"this.blur()\"><div class=\"close\" border=\"0\"></div></a></td></tr><tr><td height=\"22\" align=\"center\" valign=\"bottom\"><span class=\"warehoustitle\">{0}</span></td></tr></table></td></tr><tr><td class=\"warehousbg_02\"><div id=\"warehouscontent\"><table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"5\"><tr><td colspan=\"5\" height=\"10\"></td></tr>", StrWhDescr);
            StrEnd.Append(" <tr><td class=\"warehousbg_03\">&nbsp;</td></tr></table>");
            base.Response.Clear();
            base.Response.StatusCode = 200;
            base.Response.StatusDescription = "OK";
            base.Response.ContentType = "text/html";
            base.Response.Write(StrBegin.ToString() + StrHtml + StrEnd.ToString());
            base.Response.Flush();
            base.Response.End();
        }

        private void GetData()
        {
            DataSet dsWh = RoleFunctionServiceClientProxy.GetInstance().GetWHDataByUserID();
            StringBuilder StrHtml = new StringBuilder();
            if (dsWh.Tables[0].Rows.Count > 0)
            {
                StringBuilder Strimg = new StringBuilder();
                StringBuilder Strwh = new StringBuilder();
                for (int i = 0; dsWh.Tables[0].Rows.Count > i; i++)
                {
                    if (i == 0)
                    {
                        Strimg.Append("<tr>");
                        Strwh.Append("<tr>");
                    }
                    Strimg.AppendFormat(" <td align=\"center\"><a href=\"#\" onclick=\"Updateload('{0}','{2}','{1}');\" onFocus=\"this.blur()\"  onmousemove=\"MenuMousemove('{0}{1}{2}');\"onmouseout =\"MenuMouseout('{0}{1}{2}');\"  ><div class=\"warehouspic\" id=\"{0}{1}{2}_Div\"></div></a></td> ", dsWh.Tables[0].Rows[i]["WH_DB_ID"].ToString(), dsWh.Tables[0].Rows[i]["WH_DB_DESC"].ToString(), dsWh.Tables[0].Rows[i]["IS_GLOBAL"].ToString());
                    Strwh.AppendFormat(" <td align=\"center\"><a href=\"#\" onclick=\"Updateload('{0}','{2}','{1}');\" onFocus=\"this.blur()\"  >{1}</a></td> ", dsWh.Tables[0].Rows[i]["WH_DB_ID"].ToString(), dsWh.Tables[0].Rows[i]["WH_DB_DESC"].ToString(), dsWh.Tables[0].Rows[i]["IS_GLOBAL"].ToString());
                    decimal CS00001 = (i + 1) / 5M;
                    if (Regex.IsMatch(CS00001.ToString(), @"^[1-9]\d*$"))
                    {
                        Strimg.Append(" </tr>");
                        Strwh.Append("</tr>");
                        StrHtml.Append(Strimg.ToString() + Strwh.ToString());
                        Strimg.Remove(0, Strimg.Length);
                        Strwh.Remove(0, Strwh.Length);
                        Strimg.Append("<tr>");
                        Strwh.Append("<tr>");
                    }
                }
                Strimg.Append(" </tr>");
                Strwh.Append("</tr>");
                StrHtml.Append(Strimg.ToString() + Strwh.ToString());
                Strimg.Remove(0, Strimg.Length);
                Strwh.Remove(0, Strwh.Length);
            }
            else
            {
                StrHtml.Append("<tr><td>Sorry No Data! </td></tr>");
            }
            StrHtml.Append(" </tr></table>");
            this.AjaxResponse(StrHtml.ToString());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((base.UserInfo == null) && (this.Session["UserInfo"] == null))
            {
                base.Response.Clear();
                base.Response.StatusCode = 200;
                base.Response.StatusDescription = "OK";
                base.Response.ContentType = "text/html";
                base.Response.Write("SessionLose");
                base.Response.Flush();
                base.Response.End();
            }
            this.Page.Response.Buffer = false;
            this.Page.Response.Cache.SetNoStore();
            if (base.Request.QueryString["TYPE"].ToString() == "GETWH")
            {
                this.GetData();
            }
        }
    }
}

